package com.aic.aicdetactor.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;

import android.text.method.DateTimeKeyListener;

public class LogUtil {

	private String _fileName = "/sdcard/AIC8600/Crash/Error.txt";
	private static LogUtil _instance = null;

	private LogUtil() {

	}

	public static LogUtil GetInstance() {
		if (LogUtil._instance == null)
			LogUtil._instance = new LogUtil();
		return LogUtil._instance;
	}

	public void append(Exception e) {
		File f = new File(_fileName);
		if (!f.exists()) {
			try {
				f.createNewFile();
			} catch (IOException ioe) {
			}
		}
		PrintStream ps = null;
		try {
			ps = new PrintStream(f);
			ps.append("[" + DateUtil.getCurrentDate() + "]");
			e.printStackTrace(ps);
		} catch (Exception ex) {
		} finally {
			if (ps != null)
			ps.close();
		}
	}

	public void append(String content) {
		File f = new File(_fileName);
		if (!f.exists()) {
			try {
				f.createNewFile();
			} catch (IOException e) {
			}
		}
		FileWriter fw = null;
		try {
			fw = new FileWriter(f, true);
			fw.append("[" + DateUtil.getCurrentDate() + "]" + content + "\n");
			fw.flush();
		} catch (IOException e) {

		} finally {
			if (fw != null) {
				try {
					fw.close();
				} catch (IOException e) {
				}
			}
		}
	}

}
